package com.tydic.springboot.service.impl;

import com.tydic.springboot.mapper.admindb.SysMapper;
import com.tydic.springboot.service.StudentSertvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentSertviceImpl implements StudentSertvice {

    @Autowired
    private SysMapper studentMapper;

    @Override
    public /*synchronized*/ List<Map<String, Object>> getAllStudent() {
        return studentMapper.getZynr();
    }

    /*@Override
    public *//*synchronized*//* List<Student> getAllStudent() {
        //字符串的序列化器
        RedisSerializer redisSerializer = new StringRedisSerializer();
        redisTemplate.setKeySerializer(redisSerializer);

        //高并发条件下，此处有点问题：缓存穿透
        //查询缓存
        List<Student> studentList = (List<Student>)redisTemplate.opsForValue().get("allStudents");

        //双重检测锁
        if (null == studentList) {
            synchronized (this) {
                //从redis获取一下
                studentList = (List<Student>)redisTemplate.opsForValue().get("allStudents");
                if (null == studentList) {
                    System.out.println("查询的数据库........");
                    //缓存为空，查询一遍数据库
                    studentList = studentMapper.selectAllStudent();
                    //把数据库查询出来的数据，放入redis中
                    redisTemplate.opsForValue().set("allStudents", studentList);
                } else {
                    System.out.println("查询的缓存.......");
                }
            }
        } else {
            System.out.println("查询的缓存.......");
        }
        return studentList;
    }*/

}